<template>
    <div class="table">
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="id" label="编号" width="80" align="center" />
            <el-table-column prop="product.name" label="商品名称" width="180" align="center" />
            <el-table-column label="货号" width="100">
                <template #default="scope">
                    NO.{{ scope.row.product.detailTitle }}
                </template>
            </el-table-column>
            <el-table-column prop="product.price" label="商品价格" width="100">
                <template #default="scope">
                </template>
            </el-table-column>
            <el-table-column prop="flashPromotionPrice" label="秒杀价" align="center" />
            <el-table-column prop="flashPromotionCount" label="秒杀数量" align="center" />
            <el-table-column prop="flashPromotionLimit" label="限购数量" align="center" />
            <el-table-column prop="sort" label="排序" align="center" />
            <el-table-column label="操作" align="center">
                <template #default="scope">
                    <div class="tanxin" style="width: 70%;margin: 0 auto;color: skyblue;">
                        <a @click="onclick(scope.row)">编辑</a>
                        <a @click="deleton(scope.row.id)">删除</a>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <div style="margin-right: 0;">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
                layout="prev, pager, next" :total="pagination.total" v-model:current-page="pagination.pageNum"
                v-model:page-size="pagination.pageSize" />
        </div>

    </div>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
import dayjs from 'dayjs'
import * as api from '../request/api'
import useTabel from '../hooks/useGoods'
import { useRoute } from 'vue-router'

import { ElTable, ElMessage } from 'element-plus'
console.log(useRoute().query);
const emits = defineEmits<{
    (event: 'chuanid', row: any): void
}>()
let { tableData, getTableData, pagination, handleSizeChange, handleCurrentChange } = useTabel(api.yxadmin.ProductRelationList,
    {
        ...useRoute().query
    })
interface iii {
    product?: any
    flashPromotionCount?: number
    flashPromotionId?: number
    flashPromotionLimit?: number
    flashPromotionPrice?: number
    flashPromotionSessionId?: number
    id?: number
    productId?: number
    sort?: number
}
let onclick = (row: iii) => {
    // console.log(id);
    emits('chuanid', row)
}
let deleton = async (id: number) => {
    // DeleteFlashProduct
    await api.yxadmin.DeleteFlashProduct(id)
    getTableData()
    ElMessage({
        type: 'success',
        message: '操作成功',
    })
}
</script>

<style scoped>
.table {
    margin: 20px;
    border: 1px solid #eee;
}
</style>